/*
 * Copyright © 2011 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation. 
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners. 
 * See LICENSE.TXT for license information.
 */ 

package com.nokia.example.wordpress.networking;

/**
 * Operation to delete a comment.
 */
public class DeleteCommentOperation extends NetworkOperation {

    /**
     * Listener interface
     */
    public interface Listener {

        /**
         * Returns the status of the delete operation.
         * @param status True if success, false otherwise
         */
        public void commentDeleted(boolean status);
    }
    private static final String WP_DELETE_COMMENT = "wp.deleteComment";
    private Comment comment;
    private Listener listener;

    /**
     * Constructor
     * @param listener
     * @param post Parent post for the comment
     * @param content Comment content
     */
    public DeleteCommentOperation(Listener listener, Comment comment) {
        this.listener = listener;
        this.comment = comment;
    }

    /**
     * Starts the operation
     */
    public void start() {
        Request req = new Request(WP_DELETE_COMMENT);
        req.addStringParam(comment.post.blog.blogId);
        req.addStringParam(comment.post.blog.blogUser);
        req.addStringParam(comment.post.blog.blogUserPassword);
        req.addStringParam(comment.commentId);
        Network nw = new Network(this);
        nw.startHttpPost(comment.post.blog.xmlrpcUrl, req.request());
    }

    /**
     * Parses the server response and calls the listener.
     * @param response
     */
    public void networkHttpPostResponse(String response) {
        // Assume that everything went ok while deleting.
        System.out.println("delete comment: " + response);
        if (listener != null) {
            listener.commentDeleted(true);
        }
    }
}
